<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig">
			<!-- 申请 -->
			<template #applicationFile="{ row }">
				<el-text v-if="row.applicationFile" type="primary" @click="openArchival('apply', row)" style="cursor: pointer"> 已归档 </el-text>
				<el-text v-else type="danger" style="cursor: pointer"> 未归档 </el-text>
			</template>
			<!-- 评估 -->
			<template #estimateTable="{ row }">
				<el-text v-if="row.estimateTable" type="primary" @click="openArchival('assess', row)" style="cursor: pointer"> 已归档 </el-text>
				<el-text v-else type="danger" style="cursor: pointer"> 未归档 </el-text>
			</template>
			<!-- 实施 -->
			<template #transformTable="{ row }">
				<el-text v-if="row.transformTable" type="primary" @click="openArchival('implement', row)" style="cursor: pointer"> 已归档 </el-text>
				<el-text v-else type="danger" style="cursor: pointer"> 未归档 </el-text>
			</template>
			<!-- 验收 -->
			<template #checkTable="{ row }">
				<el-text v-if="row.checkTable" type="primary" @click="openArchival('accept', row)" style="cursor: pointer"> 已归档 </el-text>
				<el-text v-else type="danger" style="cursor: pointer"> 未归档 </el-text>
			</template>
		</aplid-base-crud>
		<AplidDialog title="查看" v-model="showView">
			<DetailPage v-laoding="loading" v-bind="config" :model="formModel"></DetailPage>
		</AplidDialog>
		<!-- 实施详情 -->
		<AplidDialog title="查看" v-model="implementShow">
			<DetailPart :nowRowData="copRowData"></DetailPart>
		</AplidDialog>
	</BaseContainer>
</template>

<script setup lang="ts">
import { baseConfig } from './config'
import { ref, reactive, toRefs, onMounted } from 'vue'
import { acceptFormConfig } from '../accept/config'
import { applyFormConfig } from '../apply/config'
import { assessConfig } from '../assess/config'
import DetailPart from '../implement/detailPart/index.vue'
import DetailPage from '@/views/aplid/DetailPage/index.vue'
import apiMod from '@/apiMod/index'
import {getAreaObj} from '@/utils/util'
import {cloneDeep} from 'lodash-es'

let config = ref({})
let formModel:any = ref({})
let showView = ref(false)
let implementShow = ref(false)

let loading = ref(false)
let copRowData = ref({})
const openArchival = (type, row) => {
	copRowData.value = cloneDeep(row)
	loading.value = true
	formModel.value = {}
	if (type == 'accept') {
		config.value = acceptFormConfig
		// 调用接受表
		apiMod.view_bscAdaptOldAcceptance_page({ mainId: row.id }).then((res) => {
            formModel.value = res.data.records[0]
			loading.value = false
        }).catch(() => {
			loading.value = false
        })
	}
	if (type == 'apply') {
		config.value = applyFormConfig
		// 调用申请表
		apiMod.view_bscAdaptOldApply_page({ mainId: row.id }).then((res) => {
            formModel.value = res.data.records[0]
            let cr_areas:any = getAreaObj(formModel.value,'cr','set')
            let areas:any = getAreaObj(formModel.value,'','set')
			formModel.value.cr_areas = cr_areas.areaIds
			formModel.value.cr_areas_name = cr_areas.names
			formModel.value.areas = areas.areaIds
			formModel.value.areas_name = areas.names
			loading.value = false
        }).catch(() => {
			loading.value = false
        })
	}
	if (type == 'assess') {
		config.value = assessConfig
		// 调用评估表
		apiMod.view_bscAdaptOldAssessment_page({ mainId: row.id }).then((res) => {
            formModel.value = res.data.records[0]
			loading.value = false
        }).catch(() => {
			loading.value = false
        })
	}
	if (type == 'implement') {
		implementShow.value = true
		// 调用实施表
		apiMod.view_bscAdaptOldImplementation_page({ mainId: row.id }).then((res) => {
            formModel.value = res.data.records[0]
			loading.value = false
        }).catch(() => {
			loading.value = false
        })
	}
	if (type != 'implement') {
		showView.value = true
	}
}
</script>
<style scoped lang="scss"></style>
